{extend name="base"/}
{block name="resources"}
{/block}
{block name="main"}
<!--<div class="layui-collapse ns-tips">
    <div class="layui-colla-item">
        <h2 class="layui-colla-title">操作提示</h2>
        <ul class="layui-colla-content layui-show">
            <li>当前页面针对入驻申请进行管理，可以针入驻申请进行审核通过，审核拒绝操作。</li>
        </ul>
    </div>
</div>-->

<div class="ns-screen layui-collapse" lay-filter="selection_panel">
    <div class="layui-colla-item">
        <h2 class="layui-colla-title">筛选</h2>

        <form class="layui-colla-content layui-form layui-show">

            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">申请人昵称：</label>
                    <div class="layui-input-inline">
                        <input type="text" id="search_text" name="search_text" placeholder="申请人昵称" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">系统编号：</label>
                    <div class="layui-input-inline">
                        <input type="text" id="apply_no" name="apply_no" placeholder="系统编号" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>

            <input type="hidden" name="apply_state" />
            <div class="ns-form-row">
                <button class="layui-btn ns-bg-color" lay-submit lay-filter="search">筛选</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </form>

    </div>
</div>

<div class="layui-tab ns-table-tab" lay-filter="apply_list_tab">
    <ul class="layui-tab-title">
        <li class="layui-this" lay-id="">全部</li>
        <li lay-id="0" data-type="apply_state">待审核</li>
        <li lay-id="1" data-type="apply_state">已审核</li>
        <!--<li lay-id="0" data-type="apply_state">平台审核</li>
        <li lay-id="1" data-type="apply_state">待提交汇付</li>
        <li lay-id="2" data-type="apply_state">签署合同</li>
        <li lay-id="3" data-type="apply_state">缴纳费用</li>
        <li lay-id="4" data-type="apply_state">加盟成功</li>-->
    </ul>
    <div class="layui-tab-content">
        <table id="apply_list" lay-filter="apply_list"></table>
    </div>
</div>


<!-- 工具栏操作 -->
<script type="text/html" id="action">
    <div class="ns-table-btn">
        {{#  if(d.huifu_audit_status == 0){  }}
        <a class="layui-btn" lay-event="submit_huifu">提交汇付</a>
        {{#  }  }}



        {{#  if(d.apply_state == 0){ }}
        <a class="layui-btn" href="javascript:mrnaAudit('{{d.apply_id}}')">审核</a>
        {{#  } }}



        {{#  if(d.apply_state == 2){ }}
        <a class="layui-btn" href="javascript:mrnaSign('{{d.apply_id}}')">签署</a>
        {{#  } }}


        <a class="layui-btn" lay-event="apply_detail">加盟信息</a>
    </div>
</script>

<!--<script type="text/html" id="action">
    <div class="ns-table-btn">
        {{#  if(d.huifu_audit_status == 0){  }}
        <a class="layui-btn" lay-event="submit_huifu">提交汇付</a>
        {{#  }  }}

        {{#  if(d.apply_state == 0){ }}
        <a class="layui-btn" href="javascript:mrnaAudit('{{d.apply_id}}')">审核</a>
        {{#  } }}

        {{#  if(d.apply_state == 1){ }}

        {{#  } }}


        {{#  if(d.apply_state == 2){ }}
        <a class="layui-btn" href="javascript:mrnaSign('{{d.apply_id}}')">签署</a>
        {{#  } }}
        <a class="layui-btn" lay-event="apply_detail">加盟信息</a>
    </div>
</script>-->

<!-- 申请状态 -->
<script type="text/html" id="apply_state_name">
    {{#  if(d.apply_state == 0){ }}
    <span style="color: gray;">平台审核</span>
    {{#  } }}
    {{#  if(d.apply_state == 1){ }}
    <span style="color: red;">待提交汇付</span>
    {{#  } }}
    {{#  if(d.apply_state == 2){ }}
    <span style="color: red;">签署合同</span>
    {{#  } }}
    {{#  if(d.apply_state == 3){ }}
    <span style="color: green;">缴纳费用</span>
    {{#  } }}
    {{#  if(d.apply_state == 4){ }}
    <span style="color: green;">加盟成功</span>
    {{#  } }}

    {{#  if(d.apply_state == 6){ }}
    <span style="color: green;">审核驳回</span>
    {{#  } }}

</script>

<!-- 用户信息 -->
<script type="text/html" id="userdetail">
    <div class='ns-table-tuwen-box'>
        <div class='ns-img-box'>
            {{# if (d.headimg != ""){ }}
            <img layer-src src="{{ns.img(d.headimg)}}">
            {{# } else { }}
            <img layer-src src="{:img($default_img.default_headimg)}">
            {{# } }}
        </div>
        <div class='ns-font-box'>
            <p class="layui-elip">{{d.nickname}}</p>
        </div>
    </div>
</script>


{/block}
{block name="script"}
{include file="mrna/audit_action" /}
{include file="mrna/sign_action" /}
<script>
    var element,laytpl;
    layui.use(['form', 'layer', 'laydate', 'element','laytpl'], function() {
        var table, table_website,
            laytpl = layui.laytpl,
            form = layui.form,
            layer = layui.layer,
            element = layui.element,
            laydate = layui.laydate;
        form.render();

        //渲染时间
        laydate.render({
            elem: '#start_time',
            type: 'datetime'
        });

        laydate.render({
            elem: '#end_time',
            type: 'datetime'
        });


        //监听Tab切换，以改变地址hash值
        element.on('tab(apply_list_tab)', function () {
            var type = this.getAttribute('data-type');
            if (type) {
                var id = this.getAttribute('lay-id');
                $("input[name='" + type + "']").val(id);
                $("button[lay-filter='search']").click()
            } else {
                $("input[name='apply_state']").val("");
                $("button[lay-filter='search']").click()
            }
        });

        /**
         * 表格加载
         */
        table = new Table({
            elem: '#apply_list',
            url: ns.url("admin/mrna/lists"),
            parseData: function(res) { //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.message, //解析提示文本
                    "count": res.data.count, //解析数据长度
                    "data": res.data.list //解析数据列表
                };
            },
            cols: [
                [ //表头
                {
                    width:'30%',
                    field: 'userdetail',
                    title: '申请人信息',
                    unresize: 'false',
                    templet: '#userdetail',
                },
                {
                    field: 'apply_no',
                    title: '编号',
                    width: '20%',
                    unresize: 'false'
                },{
                    width:'10%',
                    field: 'apply_state_name',
                    title: '状态',
                    unresize: 'false',
                    templet: '#apply_state_name',
                },  {
                    width:'13%',
                    field: 'create_time',
                    title: '申请时间',
                    unresize: 'false',
                    templet: function(data) {
                        return ns.time_to_date(data.create_time);
                    },
                }, {
                    width:'15%',
                    title: '操作',
                    toolbar: '#action',
                    unresize: 'false'
                }
                ]
            ]
        });

        /**
         * 搜索功能
         */
        form.on('submit(search)', function(data) {
            table.reload({
                page: {
                    curr: 1
                },
                where: data.field
            });
            return false;
        });

        /**
         * 监听工具栏操作
         */
        table.tool(function(obj) {
            var data = obj.data,
                event = obj.event;
            switch (event){
                case 'apply_detail':  //认证信息
                    location.href = ns.url("admin/mrna/detail?apply_id=" +data.apply_id)
                    break;
                case 'submit_huifu': //删除
                    submitHuifu(data.apply_id);
                    break;
            }
        });

        /**
         * 删除
         */
        function submitHuifu(apply_id) {
            if (repeat_flag) return false;
            repeat_flag = true;

            layer.confirm('确定要提交汇付吗?', function() {
                $.ajax({
                    url: ns.url("admin/mrna/submitHuifu"),
                    data: {apply_id: apply_id},
                    dataType: 'JSON',
                    type: 'POST',
                    success: function(res) {
                        layer.msg(res.message);
                        repeat_flag = false;

                        if (res.code == 0) {
                            table.reload();
                        }
                    }
                });
            }, function () {
                layer.close();
                repeat_flag = false;
            });
        }
    });


</script>
{/block}